# Definition for singly-linked list.
from typing import Optional
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution:
    def swapPairs(self, head: Optional[ListNode]) -> Optional[ListNode]:
        if head == None:
            return head
        if head.next==None:
            return head


        current=ListNode(0)
        head2=current
        flag1=head
        flag2=head.next

        while flag2:
            # print(flag2.val)

            current.next=flag2
            flag1.next=flag2.next
            flag2.next=flag1
            current=flag1

            if(flag1.next)==None:
                head2 = head2.next
                return head2
            flag2=flag1.next.next
            flag1=flag1.next

        head2=head2.next
        return head2

node7=ListNode(7)
node6=ListNode(6,None)
node5=ListNode(5,node6)
node4=ListNode(4,node5)
node3=ListNode(3,node4)
node2=ListNode(2,node3)
node1=ListNode(1,node2)


lll=Solution()
lll2=lll.swapPairs(node1)
while lll2:
    print(lll2.val)
    lll2=lll2.next



